package org.jeecg.common.util.xinyuan;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.*;

public class Test {

    public static void main(String[] args) {
        //仅供参考，请根据实际接口封装参数
        String secret_key="secretkey11111";
        String iv="iv22222222222222";
        //保函申请
        TreeMap paraMap = new TreeMap();
        paraMap.put("method", "apply_guarantee");
        paraMap.put("access_key","XXXX_001");
        paraMap.put("created", "20220417142000");
        //data 数据封装
        Map dataMap = new HashMap();
        dataMap.put("apply_no","bh11222333");
        dataMap.put("enterprise_name","企业名称");
        dataMap.put("enterprise_code","qydm23434");
        dataMap.put("enterprise_address","企业注册地址");
        dataMap.put("legal_name","法人姓名");
        dataMap.put("legal_code","法人身份证号");
        dataMap.put("bank_name","开户行名称");
        dataMap.put("bank_account","23456456");
        dataMap.put("bank_code","8765423454");
        dataMap.put("callback", "");
        dataMap.put("project_name","项目名称2345");
        dataMap.put("project_code","项目编号");
        dataMap.put("project_area","项目所在区域");
        dataMap.put("project_address","项目详细地址");
        dataMap.put("section_name","标包名称");
        dataMap.put("section_code","标包编号");
        dataMap.put("tenderer","招标人");
        dataMap.put("tenderer_code","采购人统一社会信用代码");
        dataMap.put("agency","招标代理");
        dataMap.put("agency_code","招标代理统一社会信用代码");
        dataMap.put("tenderer_address","采购人地址");
        dataMap.put("tender_bond","2000");
        dataMap.put("open_time","202206011030");
        dataMap.put("tender_expire","120");
        dataMap.put("agent_name","经办人姓名");
        dataMap.put("agent_id_no","经办人证件号码");
        dataMap.put("agent_phone","经办人手机号");
        dataMap.put("agent_email","123@163.com");

        //附件
        List fjlist = new ArrayList();
        Map fileMap1 = new HashMap();
        fileMap1.put("file_name", "文件名1");
        fileMap1.put("file_type", "1");
        fileMap1.put("file_url", "文件下载地址1");
        fjlist.add(fileMap1);

        Map fileMap2 = new HashMap();
        fileMap2.put("file_name", "文件名2");
        fileMap2.put("file_type", "2");
        fileMap2.put("file_url", "文件下载地址2");
        fjlist.add(fileMap2);

        Map fileMap3 = new HashMap();
        fileMap3.put("file_name","文件名3");
        fileMap3.put("file_type","3");
        fileMap3.put("file_url","文件下载地址3");
        fjlist.add(fileMap3);

        dataMap.put("file_list",fjlist);

        String data = JSON.toJSONString(dataMap);
        data = AES.encrypt(data,secret_key,iv);//AES加密

        paraMap.put("data",data);
        String sign = Utils.createSign(paraMap,secret_key);

        paraMap.put("sign",sign);
        String raw = JSON.toJSONString(paraMap);
        System.out.println("data加密后========:"+raw);
        //data解密=================
        JSONObject jsobj  = JSONObject.parseObject(raw);
        String backdata = AES.decrypt(jsobj.getString("data"),secret_key,iv);//AES解密
        JSONObject dataobj = JSONObject.parseObject(backdata);
        System.out.println("data解密后dataobj=====:"+dataobj);
        //验签
        boolean b = Utils.checkSign(jsobj, secret_key);
        System.out.println("验签结果:"+b);
    }

}
